package sf.database.template.mybatis.ext;

import org.apache.ibatis.scripting.xmltags.DynamicContext;
import org.apache.ibatis.scripting.xmltags.SqlNode;
import sf.database.template.TemplateConstants;

import java.util.Map;

public class PageIgnoreNode  implements SqlNode {
    private final SqlNode contents;

    public PageIgnoreNode(SqlNode contents) {
        this.contents = contents;
    }

    @Override
    public boolean apply(DynamicContext context) {
        Map<String, Object> map = context.getBindings();
        Boolean bool = (Boolean) map.get(TemplateConstants.SQL_COUNT_KEY);
        if (bool != null && !bool) {
            contents.apply(context);
        }else {
            return false;
        }
        return true;
    }
}
